package alg20250304;

public class Text2 {
    public int[] searchRange(int[] nums, int target) {
        int t = searchLeft(nums, target);
        if(nums[t] != target) return new int[]{-1, -1};
        return new int[]{t, searchRight(nums, target)};
    }
    public int searchLeft(int[] nums, int target){
        int left = 0, right = nums.length - 1;
        while(left < right){
            int mid = left + (right - left) / 2;
            if(nums[mid] < target) {
                left = mid + 1;
            }else{
                right = mid;
            }
        }
        return left;
    }

    public int searchRight(int[] nums, int target){
        int left = 0, right = nums.length - 1;
        while(left < right){
            int mid = left + (right - left + 1) / 2;
            if(nums[mid] <= target){
                left = mid;
            }else {
                right = mid - 1;
            }

        }
        return right;
    }
}
